<template>
  <div class="index">
    <head-nav />
    <div class="main">
      <LeftMenu />
      <router-view />
    </div>
  </div>
</template>

<script>
import jwt_decode from 'jwt-decode'
import HeadNav from '../components/HeadNav.vue';
import LeftMenu from '../components/LeftMenu.vue';
export default {
  name: 'index',
  components: { HeadNav, LeftMenu },
  created () {
    if (localStorage.eleToken) {
      const decode = jwt_decode(localStorage.eleToken)
      //token存储到vuex中
      this.$store.dispatch('setAuthenticated', !this.isEmpty(decode))
      this.$store.dispatch('setUser', decode)
    }
  },
  methods: {
    isEmpty (value) {
      return (
        value === undefined || value === null ||
        (typeof value === 'object' && Object.keys(value).length === 0) ||
        (typeof value === 'string' && value.trim().length === 0)
      )
    },
  }
}
</script>

<style>
body {
  margin: 0;
  padding: 0;
}
.index {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}
.main {
  width: 100%;
  display: flex;
  height: 100vh;
}
</style>